﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace DAL
{
  public  class DBHelper
    {
        //private string strCon = "server=211.149.235.97;database=LibrarianDB;uid=sa;pwd=Jw2006.";
       private string strCon = "server=.;database=LibrarianDB;uid=sa;pwd=123456";
        public DataSet GetData(string sql)
        {
            using (SqlConnection con = new SqlConnection(strCon))
            {
                DataSet ds = new DataSet();
                //1创建数据库连接
                //SqlConnection con = new SqlConnection(strCon);
                //2打开数据库连接
                con.Open();
                //3操作数据
                SqlDataAdapter sda = new SqlDataAdapter(sql, con);
                sda.Fill(ds);
                //4关闭数据库连接
                con.Close();
                return ds;
            }
            
        }
        public bool SetData(string sql)
        {
            using (SqlConnection con = new SqlConnection(strCon))
            {
                bool result = false;
                //1创建数据库连接
                //SqlConnection con = new SqlConnection(strCon);
                //2打开数据库连接
                con.Open();
                //3操作数据
                SqlCommand cmd = new SqlCommand(sql, con);
                result = cmd.ExecuteNonQuery() > 0;
                //4关闭数据库连接
                con.Close();
                return result;
            }
        }
    }
}
